package cqut.wys.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by wuyoushan on 2017/11/20.
 */
public abstract class ThreadPool {

    private static ThreadFactory nameThreadFactory =new ThreadFactoryBuilder()
            .setNameFormat("crawler-thread-%d").build();

    private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(4,64,0L,
            TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(1024),nameThreadFactory);

    /**
     * 线程池执行
     *
     * @param runnable Runnable对象
     */
    public static void threadExec(Runnable runnable){
        threadPoolExecutor.execute(runnable);
    }
}
